package com.mtsmda.chapter5;

public class ContinueEx {

	private static final int CONTINUE = 0;
	private static final int BREAK = 1;

	public static void main(String[] args) {

		for (int i = 0; i < 10; i++) {
			System.out.println("i = " + i);
			continue;
		}

		System.out.println("---------");

		for (int i = 100; i > 50; i--) {
			if (i <= 97 && i >= 79) {
				continue;
			}
			System.out.println("i = " + i);
		}

		System.out.println("---------");

		boolean isBool = true;
		while (true) {
			if (isBool) {
				System.out.println("isBool");
				break;
			}
		}
		
		System.out.println("---------");

		for (int i = 80; i < 100; i--) {
			System.out.println("i = " + i);
			if (i > 50) {
				if (false) {
					if (true) {
						System.out.println("very deeply!");
						break;
					}
				} else {
					if (i > 0) {
						System.out.println("i > 0");
						if (i >= 50) {
							System.out.println("i >= 50");
							break;
						}
					}
				}
			}
		}

		System.out.println("after for statement");

		// labeled continue and break;
		System.out.println("labeled continue and break\n");
		labeledContinueOrBreak(CONTINUE);
		labeledContinueOrBreak(BREAK);
		loop();
		
		System.out.println("**************");
		exercise52();
		
		System.out.println("-----------------");
		
		for(int i = 0; i < 128; i++){
			System.out.println(i + " - " + (char)i);
		}
		
		int c = 9;
		int v = 5;
		if(c > 5){
			System.out.println(">");
		}else{
			System.out.println("<=");
		}
		
		System.out.println( (21 | 7) );
		
		while(c > 0){
			System.out.println("c = " + c);
			c--;
		}
		
	}

	static void labeledContinueOrBreak(int continueOrBreak) {
		boolean isTrue = true;
		if (continueOrBreak == CONTINUE) {
			loop: for (int i = 0; i < 5; i++) {
				if (isTrue) {
					System.out.println("innermost " + i);
					break loop;
				}
				System.out.println("Inner FOR");
			}
			System.out.println("after labeledBreak for statement");
		} else if (continueOrBreak == BREAK) {
			loop: for (int i = 0; i < 5; i++) {
				if (isTrue) {
					System.out.println("innermost " + i);
					continue loop;
				}
				System.out.println("Inner FOR");
			}
			System.out.println("after labeledContinue for statement");
		}
	}

	static void loop(){
		int [][] v = new int[][]{{11, 58, 36, 34, 254}, {15, 125}, {19}, {2533, 15}, {15, 93, 789}};
		for(int i = 0; i < v.length; i++){
			for(int j = 0; j < v[i].length ; j++){
				if(i == 2 && j == 0){
					System.out.println("break");
					break;
				}
				System.out.println( i + " x " + j);
			}
		}
		System.out.println("__________");
		System.out.println("labeled break");
		labeledBreak:
		for(int i = 0; i < v.length; i++){
			for(int j = 0; j < v[i].length ; j++){
				if(i == 2 && j == 0){
					System.out.println("break");
					break labeledBreak;
				}
				System.out.println( i + " x " + j);
			}
		}
		System.out.println("after labeledBreak");
	}
	
	static void exercise52(){
		int age = 21;
		int currentAge = 0;
		outer:
			while(currentAge <= age){
				currentAge++;
				if(currentAge == 16){
					System.out.println(currentAge + " get you driver's license");
					continue outer;
				}else{
					System.out.println(currentAge + " another year!");
				}
				
			}
		
	}
}